using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TurretManager : MonoBehaviour {
    public float interval = 3.0f;   //duration between laser shots, in seconds

    private float timer;
    private static List<GameObject> turrets;

	// Use this for initialization
	void Start () {
        timer = 0;
	}
	
	// Update is called once per frame
	void Update () {
        timer += Time.deltaTime;
        foreach (GameObject t in turrets)
            t.GetComponent<Turret>().SetRotationTimer(timer / interval);
        if (timer > interval)
        {
            foreach (GameObject t in turrets)
                t.GetComponent<Turret>().Fire();
            while (timer > interval) timer -= interval;
            Debug.Log("TurretManager::Update(): fire everything!");
        }
	}

    public static void Register(GameObject turret)
    {
        if (null == turrets) turrets = new List<GameObject>();

        if (turret.GetComponent<Turret>())
            turrets.Add(turret);
        else
            Debug.Log("TurretManager::Register(): GameObject does not have a Turret behavior!");
    }
}
